/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BUS;

import DAO.ContactGroupDAO;
import DTO.ContactGroupDTO;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author trquanglong
 */
public class ContactGroupBUS {

    /**
     * add contact group to database.
     * @param nameGroup
     * @throws java.io.UnsupportedEncodingException
     */
    static public void addContactGroup(String nameGroup) throws UnsupportedEncodingException {
        try {
            ContactGroupDAO.addContactGroup(nameGroup);
        } catch (SQLException ex) {
            Logger.getLogger(TasksBUS.class.getName()).log(Level.SEVERE, null, ex);
            return;
        }
    }

    /**
     * get all of contact groups.
     * @return
     */
    public static ArrayList<ContactGroupDTO> getListContactGroup() {
        ArrayList<ContactGroupDTO> lstGroup = new ArrayList<ContactGroupDTO>();
        try {
            lstGroup = ContactGroupDAO.getListContactGroup();
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactGroupBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lstGroup;
    }

    /**
     * get ID group by name.
     * @param nameGroup
     * @return
     */
    public static int getIDGroup(String nameGroup) {
        try {
            return ContactGroupDAO.getIDGroup(nameGroup);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactGroupBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return -1;
    }

    /**
     * detele group by name.
     * @param nameGroup
     */
    public static void deleteGroup(String nameGroup) {
        try {
            try {
                ContactGroupDAO.deleteGroup(nameGroup);
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(ContactGroupBUS.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ContactGroupBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
